<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('退款单列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <input type="hidden" name="type" value="1"/>
                    <ul>
                        <li>
                            <label>状态：</label>
                            <select name="status"  th:with="type=${@dict.getType('refuseStatus')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <!--<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:refuse:add">-->
            <!--<i class="fa fa-plus"></i> 添加-->
            <!--</a>-->
            <!--<a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:refuse:edit">-->
            <!--<i class="fa fa-edit"></i> 修改-->
            <!--</a>-->
            <!--<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:refuse:remove">-->
            <!--<i class="fa fa-remove"></i> 删除-->
            <!--</a>-->
            <!--<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:refuse:export">-->
            <!--<i class="fa fa-download"></i> 导出-->
            <!--</a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:refuse:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:refuse:remove')}]];
    var statusDatas = [[${@dict.getType('refuseStatus')}]];
    var prefix = ctx + "system/refuse";

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "退款单",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '主键ID',
                    visible: false
                },
                {
                    field: 'orderNo',
                    title: '订单编号'
                },
                {
                    field: 'result',
                    title: '换货原因'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'refuse',
                    title: '拒绝原因'
                },
                {
                    field: 'consigneeName',
                    title: '收货人姓名'
                },
                {
                    field: 'consigneeTel',
                    title: '收货人电话'
                },
                {
                    field: 'address',
                    title: '收货地址'
                },
                {
                    field: 'shippingName',
                    title: '物流名称'
                },
                {
                    field: 'shippingCode',
                    title: '物流单号'
                },
                {
                    field: 'mobile',
                    title: '联系电话'
                },
                {
                    field: 'notes',
                    title: '退货说明'
                },
                // {
                //     field: 'refundNo',
                //     title: '退款单号'
                // },
                // {
                //     field: 'price',
                //     title: '退款金额'
                // },
                {
                    field: 'created',
                    title: '申请时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.status==0){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="agree(\'' + row.id + '\')"><i class="fa fa-edit"></i>同意</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="refuse(\'' + row.id + '\')"><i class="fa fa-remove"></i>拒绝</a>');
                        }
                        if(row.status==3){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="agree1(\'' + row.id + '\')"><i class="fa fa-edit"></i>确认收货</a> ');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
    function agree(id) {
        layer.confirm('确认通过吗',{
            shade:[0.5,'#000'],
            shift:1,
            shadeClose:true,
            btn:['确认','取消'],
            content:'收货人姓名:<input id="consigneeName"/><hr>收货人电话:<input id="consigneeTel"/><hr>收货地址:<input id="address"/>',
            yes: function (index,layero) {
                var consigneeName = $("#consigneeName").val();
                var consigneeTel = $("#consigneeTel").val();
                var address = $("#address").val();
                //执行 Ajax 后重载
                $.ajax({
                    url : prefix+"/agree/"+id+"?consigneeName="+consigneeName+"&consigneeTel="+consigneeTel+"&address="+address,
                    type : "post",
                    success : function(result) {
                        layer.close(index)
                        $.table.search()
                    },
                    error:function () {
                        layer.msg('失败',{'icon':2});
                    }
                });
            },btn2: function (index,layero) {
            }
        })
    }

    function refuse(id) {
        layer.confirm('确认拒绝吗',{
            shade:[0.5,'#000'],
            shift:1,
            shadeClose:true,
            btn:['确认','取消'],
            yes: function (index,layero) {
                //执行 Ajax 后重载
                $.ajax({
                    url : prefix+"/refuse/"+id,
                    type : "post",
                    success : function(result) {
                        layer.close(index)
                        $.table.search()
                    },
                    error:function () {
                        layer.msg('失败',{'icon':2});
                    }
                });
            },btn2: function (index,layero) {
            }
        })
    }


    function agree1(id) {
        layer.confirm('确认收货吗',{
            shade:[0.5,'#000'],
            shift:1,
            shadeClose:true,
            btn:['确认','取消'],
            yes: function (index,layero) {
                //执行 Ajax 后重载
                $.ajax({
                    url : prefix+"/agree1/"+id,
                    type : "post",
                    success : function(result) {
                        layer.close(index)
                        $.table.search()
                    },
                    error:function () {
                        layer.msg('失败',{'icon':2});
                    }
                });
            },btn2: function (index,layero) {
            }
        })
    }
</script>
</body>
</html>